<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class GroupbookingUser extends Base
{
    use HasFactory;

    //拼团成员表
    public $table = 'groupbooking_user';

    /**
     * @param $groupbookingid
     * @param $uid
     * @return mixed
     * User: 张浩
     * Date: 2022/11/20
     * Time: 21:27
     * 根据拼团id和用户id获取数据
     */
    public static function GroupbookingUser($groupbookingid,$uid)
    {
        return self::where('groupbooking_id', $groupbookingid)
            ->where('u_id', $uid)
            ->first();
    }

    /**
     * @param $post
     * @return mixed
     * User: 张浩
     * Date: 2022/11/20
     * Time: 19:01
     * 添加拼团成员商品
     */
    public static function GroupbookingUserCreate($post)
    {
        return self::create($post);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     * User: 张浩
     * Date: 2022/11/17
     * Time: 18:50
     * 关联用户表
     */
    public function Renting()
    {
        return $this->belongsTo(Renting::class, 'u_id', 'id');
    }

    /**
     * @return mixed
     * User: 张浩
     * Date: 2022/11/17
     * Time: 18:49
     * 获取拼团成员信息
     */
    public static function wxGroupBookingDetails($id)
    {
        $list = self::with('Renting')->where('groupbooking_id', $id)->orderBy('created_at')->get()->toArray();
        if (empty($list)) return [];
        return $list;
    }

    /**
     * @param $id
     * @return int
     * User: 张浩
     * Date: 2022/11/17
     * Time: 18:48
     * 获取拼团信息人员总条数
     */
    public static function wxGroupBookinguidlist($id)
    {
        $list = self::where('groupbooking_id', $id)->orderBy('created_at')->get()->toArray();
        if (empty($list)) return 0;
        return count($list);
    }
}
